package com.xxd.spring.boot.demo.lihonghai.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxd.spring.boot.demo.lihonghai.Result;
import com.xxd.spring.boot.demo.lihonghai.entity.Classes;
import com.xxd.spring.boot.demo.lihonghai.entity.Teacher;
import com.xxd.spring.boot.demo.lihonghai.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @RequestMapping("/add")
    public Result add(@RequestBody Teacher teacher)
    {
       teacherService.add(teacher);
        return new Result().success();}

        @RequestMapping("/update")
        public Result update(@RequestBody Teacher teacher)
        {
            teacherService.updateById(teacher);
            return new Result().success();
        }

        @RequestMapping("/delete/{id}")
        public Result delete(@PathVariable("id") Integer id)
        {
            teacherService.deleteById(id);
            return new Result().success();
        }

        @RequestMapping("/listpage")
        public Result listpage(Page page, @RequestParam Map<String,Object> params)
        {
            IPage<Teacher> respage=teacherService.listPage(page,params);
            return new Result().success().setData(respage);
        }


    }

